<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/commons/jsp/taglibs.jsp"%>
<%@taglib uri="http://www.framework.com/taglib/tree" prefix="tree"%>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<link href="${ctx}/fckeditor/_samples/sample.css" rel="stylesheet" type="text/css" />
<link type="text/css" href="${ctx}/commons/js/uploadify/uploadify.css" rel="stylesheet"></link>
<style type="text/css">
	li{
		padding-top:8px;
	}
</style>
<form name="addCancelDataForm" id="addCancelResonForm" method="post" action="${ctx}/business/projectNb/saveUploadfile" >
	<input type="hidden" name="projectId" value="${projectId}"/>
	<input type="hidden" name="budgetMenuData" id="budgetMenuData" value=""/>
	<table class="infoTable">
		<tbody>
			<tr>
				<th  align='center' width="15%">评审纪要</th>
				<td style="border-right: none" width="35%">
					<div id="fileQueue11" class="fileQueue" flag="11" style="margin: 10px 0px 0px 10px">
						<input type="file" name="uploadify" class="uploadify" id="uploadify11" data-options="required:true"/>
						<p style="color: #aaaaaa;width: auto">
						1、按住Ctrl可选择多个文件上传;<br/>
						2、可上传jpg,png,gif,bmp,pdf,zip,rar类型文件<br/>
						</p>
					</div>
				</td>
				<td style="border-left: none" colspan="2">
					<c:forEach items="${resList}" var="res">
						<c:if test="${res.functionFlog==11}">
							<div><a class="easyui-linkbutton" href="${ctx}/business/projectmanage/fileView?resId=${res.id}" >${res.oldName}</a> <span style="cursor: pointer;" onclick="deleteFile(this,'${res.id}');"><img src="${ctx }/commons/themes/icons/cancel.png"/></span></div>
						</c:if>
					</c:forEach>
				</td>
				<th  align='center' width="15%">其他资料</th>
				<td style="border-right: none" width="35%">
					<div id="fileQueue28" class="fileQueue" flag="28" style="margin: 10px 0px 0px 10px">
						<input type="file" name="uploadify" class="uploadify" id="uploadify28" data-options="required:true"/>
						<p style="color: #aaaaaa;width: auto">
							1、按住Ctrl可选择多个文件上传;<br/>
							2、可上传jpg,png,gif,bmp,pdf,zip,rar类型文件<br/>
						</p>
					</div>
				</td>
				<td style="border-left: none" colspan="2">
					<c:forEach items="${resList}" var="res">
						<c:if test="${res.functionFlog==28}">
							<div><a class="easyui-linkbutton" href="${ctx}/business/projectmanage/fileView?resId=${res.id}" >${res.oldName}</a> <span style="cursor: pointer;" onclick="deleteFile(this,'${res.id}');"><img src="${ctx }/commons/themes/icons/cancel.png"/></span></div>
						</c:if>
					</c:forEach>
				</td>

			</tr>
		</tbody>
	</table>		
</form>

<script type="text/javascript">
	$(function(){
		var resIds = "";
		<c:forEach items="${resList}" var="res">
		resIds += ",${res.id}";
		</c:forEach>
		$('#budgetMenuData').val(resIds);


		$(".uploadify").each(function() {
			upload=$(this).parent().parent().parent().find(".fileName");
			fileQueue=$(this).parent().parent().parent().find(".fileQueue");
			$(this).uploadify({
				'height'        : 27,   
	            'width'         : 80,    
	            'buttonText'    : '选择附件',
	            'queueID': fileQueue.val(),//队列的ID
	            'queueSizeLimit':5,// 附件附列长度
				'swf': '${ctx}/commons/js/uploadify/uploadify.swf',
				'uploader':'${ctx}/business/projectmanage/upload;jsessionid=${pageContext.session.id}?functionFlog=6',// 上传时请求的后台处理的controller
				'cancelImg': '${ctx}/commons/js/uploadify/uploadify-cancel.png',
				'method':'post',  
				'folder': '',
				'preventCaching' : true,
				'fileTypeExts' :'*.jpg;*.png;*.gif;*.bmp;*.pdf',
				'auto': true,
				'multi': true,//是否可多选
				'removeCompleted' : false,
				'successTimeout' : 55555,
				'onUploadSuccess':function(file, data, response){
					$('#' + file.id).find('.data').html(' 上传完毕');
					$('#budgetMenuData').val($('#budgetMenuData').val() + "," + data);
					var cancel=$('#fileQueue .uploadify-queue-item[id="' + file.id + '"]').find(".cancel a");
					if (cancel) {
					   cancel.attr("rel", data);
					   cancel.click(function () {
						   var cancelData = cancel.attr("rel");
			               var  budgetMenuData = $('#budgetMenuData').val();
			               var index = budgetMenuData.indexOf(","+cancel.attr("rel"))
			               if(index != -1){
			            	   budgetMenuData = budgetMenuData.replace(","+cancelData,"");
			            	   $('#budgetMenuData').val(budgetMenuData);
			               }
					   });
					}
				},
				'onUploadStart':function(file){
					var uploadId=$('#' + file.id).parent().parent().find(".uploadify").attr("id");
					var functionFlog=$('#' + file.id).parent().parent().parent().parent().find(".fileQueue").attr("flag");
			        $("#"+uploadId).uploadify("settings","formData",{"functionFlog":functionFlog});
				},
				'onSelectError':function(file, errorCode, errorMsg){
					switch(errorCode) {
						case -110:
							this.queueData.errorMsg='所选文件大小超出系统限制!';
							break;
						case -120:
							this.queueData.errorMsg='所选文件大小异常!';
							break;
						case -130:
							this.queueData.errorMsg='所选文件类型不正确!';
							break;
					}
				},
				'onCancel' : function(file){
					alert(file);
				}
			});
		});
	});
	
	
	/**
	*删除附件
	*/
	function deleteFile(v,resId){
		var parent = v.parentNode;
		parent.parentNode.removeChild(parent);
		var  budgetMenuData = $('#budgetMenuData').val();
        var index = budgetMenuData.indexOf(","+resId)
        if(index != -1){
     	   budgetMenuData = budgetMenuData.replace(","+resId,"");
     	   $('#budgetMenuData').val(budgetMenuData);
        }

      //删除数据库中的文件信息
        $.ajax({
    		type : "post",
    		url : "${ctx}/biz/projectExt/deleteFile?resId="+resId,
    		data : top.$("#addProjectsDataForm").serialize(),
    		success : function(data){
    			
    		},
    		error : function(data){
    			alert("错误");
    		}
    	});
	}
	

	//关闭
	function afterClosed(){
		
		// 在弹出对话框内找到Uploadify插件，并隐藏之。
         top.$.find('.upload').hide();
		// 将弹出对话框还原成弹出前的状态，并清空里面的内容。
		top.$('#firstLevelDialog').dialog('destroy').empty();

	}

	
</script>
		